﻿using System;
using UnityEngine;

namespace SwanEngine.Astar
{
    /************************************************************************/
    /* 地图网格                                                                     */
    /************************************************************************/
	public class Grid
	{
        private Node startNode;
        private Node endNode;
        /// <summary>
        /// 格子行数
        /// </summary>
        public int tileRow;
        /// <summary>
        /// 格子列数
        /// </summary>
        public int tileCol;

        private int type;

        public static double STRAIGHT_COST = 1.0f;
        public static double DIAG_COST = Math.Sqrt(2.0);

        protected Node[,] nodes;
        protected bool[,] applicationCheck;

        public Grid(MapDataVo vo)
        {
            tileRow = vo.tileRow;
            tileCol = vo.tileCol;
            nodes = new Node[tileCol,tileRow];
            applicationCheck = new bool[tileCol, tileRow];
            for (int i = 0; i < vo.tileCol; i++)
            {
                for (int j = 0; j < vo.tileRow; j++)
                {
                    if ((vo.tiles[i, j] & 1) == 1)
                    {
                        nodes[i,j] = new Node(i, j);
                    }
                }
            }
        }

        public void setApplicationCheck(int x, int y, bool value)
        {
            if (x >= 0 && x < tileCol && y >= 0 && y < tileRow)
            {
                applicationCheck[x, y] = value;
            }
        }
        public Node getNode(int x, int y)
        {
            if (x >= 0 && x < tileCol && y >= 0 && y < tileRow)
            {
                if (applicationCheck[x, y] == true)
                    return null;
                return nodes[x, y];
            }

            return null;
        }
	}
}
